<template>
  <view class="">
    <image
      src="https://fangguaner.wm76.mtnet.ren/static/applet/logo.png"
      mode=""
      class="logo"
    ></image>

    <view class="usebox">
      <image
        src="https://fangguaner.wm76.mtnet.ren/static/applet/huiyuan2.png"
        mode=""
      ></image>
      <input
        type="text"
        :value="user"
        placeholder="请输入用户名"
        @input="username"
      />
    </view>
    <view class="passwordbox">
      <image
        src="https://fangguaner.wm76.mtnet.ren/static/applet/quanxian.png"
        mode=""
      ></image>
      <input
        type="text"
        value=""
        placeholder="请输入登录密码"
        @input="password"
        password=""
      />
    </view>
    <view class="login" @click="login"> 立即登录 </view>
    <image
      src="https://fangguaner.wm76.mtnet.ren/static/applet/2bb73e02147136fc3bcdb024a50568a.png"
      mode=""
      class="bottom"
    ></image>
  </view>
</template>

<script>
import { getlogin } from "../../api/api/index.js";
var WebIM = require("../../pagesA/utils/WebIM")["default"];
export default {
  data() {
    return {
      user: "",
      posswords: "",
    };
  },
  onLoad() {},
  methods: {
    username(e) {
      this.user = e.detail.value;
      uni.setStorageSync("user", this.user);
    },
    password(e) {
      this.passwords = e.detail.value;
    },
    login() {
      if (this.user == "" && this.passwords == "") {
        uni.showModal({
          title: "请输入用户名或密码",
        });
      } else {
        let dataArr = {
          user: this.user,
          password: this.passwords,
          type: 3,
        };
        getlogin(dataArr).then((res) => {
          uni.setStorageSync("token", res.data.token);
          uni.setStorageSync("identity", "经纪人");
          if (uni.getStorageSync("flag") != 1) {
            uni.setStorageSync("flag", 2);
          }
          let imData = {
            user: res.data.im.name,
            pwd: res.data.im.password,
            nickName: res.data.im.nickname,
            header_img: res.data.header_img,
          };
          uni.setStorageSync("imData", imData);
          getApp().globalData.conn.open({
            apiUrl: WebIM.config.apiURL,
            user: res.data.im.name,
            //   user: "opp123",
            pwd: res.data.im.password,
            //   grant_type: "password",
            appKey: WebIM.config.appkey,
            success: () => {
              //   this.userInfor.phone = data2.phoneNumber; //用户真实手机号
              uni.setStorageSync("myUsername", res.data.im.nickname || res.data.name);
			  this.$store.state.imLogin = true
              //   uni.setStorageSync("userInfor", this.userInfor);
              //   this.$store.commit("setUserInfor", this.userInfor);
              uni.hideLoading();
              uni.showToast({
                title: "授权登录成功",
                duration: 2000,
                mask: true,
                success: () => {
                  setTimeout(() => {
                    this.jumpLink({
                      link: "/pages/homepage/index",
                    });
                  }, 1500);
                },
              });
            },
          });
        });
      }
    },
  },
  onLoad() {
    this.user = uni.getStorageSync("user");
    console.log(this.user);
    // this.passwords=uni.getStorageSync("brokerpassword")
  },
};
</script>

<style>
/* logo */
.logo {
  width: 358rpx;
  height: 188rpx;
  margin-top: 111rpx;
  margin-left: 185rpx;
}

/* 用户名输入框*/
.usebox {
  display: flex;
  width: 600rpx;
  height: 103rpx;
  background-color: #ffffff;
  box-shadow: 0rpx 6rpx 13rpx 2rpx rgba(206, 61, 58, 0.17);
  border-radius: 52rpx;
  padding: 35rpx 0;
  box-sizing: border-box;
  margin-left: 76rpx;
  margin-top: 116rpx;
}

.usebox > image {
  width: 40rpx;
  height: 44rpx;
  margin-left: 35rpx;
}

.usebox > input {
  font-size: 30rpx;
  margin-left: 39rpx;
  width: 450rpx;
}

/* 密码输入框 */
.passwordbox {
  display: flex;
  width: 600rpx;
  height: 103rpx;
  background-color: #ffffff;
  box-shadow: 0rpx 6rpx 13rpx 2rpx rgba(206, 61, 58, 0.17);
  border-radius: 52rpx;
  padding: 35rpx 0;
  box-sizing: border-box;
  margin-top: 87rpx;
  margin-left: 76rpx;
}

.passwordbox > image {
  width: 40rpx;
  height: 44rpx;
  margin-left: 46rpx;
}

.passwordbox > input {
  font-size: 30rpx;
  margin-left: 39rpx;
  width: 450rpx;
}

.login {
  width: 600rpx;
  height: 103rpx;
  background-image: linear-gradient(-30deg, #e1312d 0%, #f8524f 99%),
    linear-gradient(#ffffff, #ffffff);
  background-blend-mode: normal, normal;
  box-shadow: 0rpx 6rpx 13rpx 2rpx;
  border-radius: 52rpx;
  text-align: center;
  line-height: 103rpx;
  font-size: 36rpx;
  font-family: MicrosoftYaHei;
  font-weight: 700;
  color: #ffffff;
  margin-left: 76rpx;
  margin-top: 97rpx;
}

.findpassword {
  font-family: MicrosoftYaHei;
  font-size: 26rpx;
  font-weight: normal;
  font-stretch: normal;
  letter-spacing: 0rpx;
  color: #ce3d3a;
  text-align: center;
  margin-top: 86rpx;
}

.bottom {
  width: 100%;
  position: absolute;
  bottom: 0;
  height: 141rpx;
}
</style>
